package com.scu.servlet;

import com.scu.dao.mPostDao;
import com.scu.entity.mPost;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;

@WebServlet("/PostAddServlet")
public class PostAddServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //拿到前端表单中输入的数据
        String post_title = request.getParameter("post_title");
        String post_content = request.getParameter("post_content");
        String type = request.getParameter("type");
        //String id = request.getParameter("id");

        Date date = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");

        System.out.println(post_title);
        mPost post = new mPost();
        post.setPost_title(post_title);
        post.setPost_content(post_content);
        post.setType(type);
        //post.setIs_illegal(0);
        post.setDates(ft.format(date));

        try {
            new mPostDao();
            mPostDao.insert(post);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        System.out.println("123");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
